/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import controlador.ControladorCliente;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import utils.Cliente;

/**
 *
 * @author Igor
 */
public class PainelGerenciarClientes extends javax.swing.JPanel {

    ArrayList<Cliente> clientes = null;
    ControladorCliente controladorCliente = new ControladorCliente();
    DefaultTableModel modelUsuarios;
    String cpfSelecionado = "";

    /**
     * Creates new form PainelGerenciarClientes
     */
    public PainelGerenciarClientes() {
        initComponents();
        modelUsuarios = (DefaultTableModel) tabelaClientes.getModel();

        this.campoBuscaCPF.setEnabled(false);
        this.campoBuscaNome.setEnabled(false);
        this.abasUsuario.setEnabledAt(0, true);
        this.abasUsuario.setEnabledAt(1, false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        barraCliente = new javax.swing.JToolBar();
        adicionarUsuario = new javax.swing.JButton();
        editarUsuario = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        abasUsuario = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        campoNomeAddCliente = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        campoCPFAddCliente = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        campoEnderecoAddCliente = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        campoTelefoneAddCliente = new javax.swing.JTextField();
        botaoConfirmarUsuario = new javax.swing.JButton();
        cancelarBotao = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        campoBuscaCPF = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        campoBuscaNome = new javax.swing.JTextField();
        buscarCliente = new javax.swing.JButton();
        atualizaCliente = new javax.swing.JButton();
        novoNome = new javax.swing.JTextField();
        novoCPF = new javax.swing.JTextField();
        novoEndereco = new javax.swing.JTextField();
        novoTelefone = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        checkCPF = new javax.swing.JCheckBox();
        checkNome = new javax.swing.JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaClientes = new javax.swing.JTable();
        selecionaCliente = new javax.swing.JButton();
        removerCliente = new javax.swing.JButton();

        barraCliente.setOrientation(javax.swing.SwingConstants.VERTICAL);
        barraCliente.setRollover(true);

        adicionarUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/addCliente.png"))); // NOI18N
        adicionarUsuario.setText("Adicionar");
        adicionarUsuario.setFocusable(false);
        adicionarUsuario.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        adicionarUsuario.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        adicionarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicionarUsuarioActionPerformed(evt);
            }
        });
        barraCliente.add(adicionarUsuario);

        editarUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/editClient.png"))); // NOI18N
        editarUsuario.setText("Editar");
        editarUsuario.setFocusable(false);
        editarUsuario.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editarUsuario.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarUsuarioActionPerformed(evt);
            }
        });
        barraCliente.add(editarUsuario);

        jPanel1.setBackground(new java.awt.Color(0, 0, 102));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 8, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setText("Adição de Clientes");

        jLabel2.setText("Nome completo:");

        jLabel3.setText("CPF/CNPJ:");

        jLabel4.setText("Endereço:");

        jLabel5.setText("Telefone:");

        botaoConfirmarUsuario.setText("Confirmar");
        botaoConfirmarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoConfirmarUsuarioActionPerformed(evt);
            }
        });

        cancelarBotao.setText("Cancelar");
        cancelarBotao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarBotaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(campoTelefoneAddCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(campoCPFAddCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE)
                            .addComponent(campoEnderecoAddCliente)
                            .addComponent(campoNomeAddCliente)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(159, 159, 159)
                        .addComponent(botaoConfirmarUsuario)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cancelarBotao)))
                .addContainerGap(414, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel1)
                .addGap(36, 36, 36)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoNomeAddCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoCPFAddCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoEnderecoAddCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoTelefoneAddCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoConfirmarUsuario)
                    .addComponent(cancelarBotao))
                .addContainerGap(312, Short.MAX_VALUE))
        );

        abasUsuario.addTab("Adicionar", jPanel2);

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel6.setText("Edição de Clientes");

        jLabel7.setText("Busque o cliente por CPF/CNPJ");

        jLabel8.setText("Busque o cliente pelo nome");

        buscarCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/search.png"))); // NOI18N
        buscarCliente.setText("Buscar");
        buscarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarClienteActionPerformed(evt);
            }
        });

        atualizaCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/edit.png"))); // NOI18N
        atualizaCliente.setText("Editar");
        atualizaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizaClienteActionPerformed(evt);
            }
        });

        jLabel9.setText("Digite os novos campos:");

        checkCPF.setText("Busque por CPF/CNPJ");
        checkCPF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkCPFActionPerformed(evt);
            }
        });

        checkNome.setText("Busque por nome");
        checkNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkNomeActionPerformed(evt);
            }
        });

        tabelaClientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "CPF/CNPJ", "Nome", "Endereço", "Telefone"
            }
        ));
        jScrollPane1.setViewportView(tabelaClientes);

        selecionaCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/select.png"))); // NOI18N
        selecionaCliente.setText("Selecionar");
        selecionaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selecionaClienteActionPerformed(evt);
            }
        });

        removerCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/remove.png"))); // NOI18N
        removerCliente.setText("Remover");
        removerCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removerClienteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(novoTelefone, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
                                    .addComponent(novoEndereco)
                                    .addComponent(novoCPF)
                                    .addComponent(novoNome)))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(selecionaCliente)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(atualizaCliente)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(removerCliente)))
                        .addGap(20, 20, 20))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel8)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(campoBuscaCPF)
                            .addComponent(campoBuscaNome, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE))
                        .addGap(43, 43, 43)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(checkCPF)
                            .addComponent(checkNome))
                        .addContainerGap())))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(192, 192, 192)
                .addComponent(buscarCliente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 321, Short.MAX_VALUE)
                .addComponent(jLabel9)
                .addGap(154, 154, 154))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoBuscaCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(checkCPF))
                .addGap(18, 18, 18)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoBuscaNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(checkNome))
                .addGap(10, 10, 10)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(54, 54, 54)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(novoNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(novoCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(novoEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(novoTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(atualizaCliente)
                                    .addComponent(selecionaCliente)
                                    .addComponent(removerCliente)))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(buscarCliente))
                .addContainerGap(229, Short.MAX_VALUE))
        );

        abasUsuario.addTab("Editar", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(barraCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(abasUsuario))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(barraCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(abasUsuario)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void adicionarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionarUsuarioActionPerformed
        abasUsuario.setSelectedIndex(0);
        this.abasUsuario.setEnabledAt(0, true);
        this.abasUsuario.setEnabledAt(1, false);
    }//GEN-LAST:event_adicionarUsuarioActionPerformed

    private void editarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarUsuarioActionPerformed
        abasUsuario.setSelectedIndex(1);
        this.abasUsuario.setEnabledAt(0, false);
        this.abasUsuario.setEnabledAt(1, true);
    }//GEN-LAST:event_editarUsuarioActionPerformed

    private void cancelarBotaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarBotaoActionPerformed
        this.campoCPFAddCliente.setText("");
        this.campoEnderecoAddCliente.setText("");
        this.campoNomeAddCliente.setText("");
        this.campoTelefoneAddCliente.setText("");
    }//GEN-LAST:event_cancelarBotaoActionPerformed

    private void botaoConfirmarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoConfirmarUsuarioActionPerformed
        if (!campoCPFAddCliente.getText().equals("") && !campoEnderecoAddCliente.equals("") && !campoNomeAddCliente.equals("") && !campoTelefoneAddCliente.equals("")) {
            controladorCliente.insereCliente(campoNomeAddCliente.getText(), campoCPFAddCliente.getText(), campoEnderecoAddCliente.getText(), campoTelefoneAddCliente.getText());
            JOptionPane.showMessageDialog(null, "Cliente adicionado com sucesso");
        } else {
            JOptionPane.showMessageDialog(null, "Todos os campos precisam ser preenchidos");
        }

        this.campoCPFAddCliente.setText("");
        this.campoEnderecoAddCliente.setText("");
        this.campoNomeAddCliente.setText("");
        this.campoTelefoneAddCliente.setText("");
    }//GEN-LAST:event_botaoConfirmarUsuarioActionPerformed

    private void buscarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarClienteActionPerformed


        if (campoBuscaNome.getText() != null && !campoBuscaNome.getText().equals("") && campoBuscaNome.isEnabled()) {
            clientes = controladorCliente.buscaClientesPorNome(campoBuscaNome.getText());
        } else if (campoBuscaCPF.getText() != null && !campoBuscaCPF.getText().equals("") && campoBuscaCPF.isEnabled()) {
            clientes = controladorCliente.buscaClientesPorCPFCNPJ(campoBuscaCPF.getText());
        } else {
            clientes = controladorCliente.buscaTodosOsClientes();
        }

        modelUsuarios.setNumRows(0);


        for (int i = 0; i < clientes.size(); i++) {
            Vector vec = new Vector();
            vec.add(0, clientes.get(i).getCpf_cnpj());
            vec.add(1, clientes.get(i).getNome());
            vec.add(2, clientes.get(i).getEndereco());
            vec.add(3, clientes.get(i).getTelefone());
            modelUsuarios.addRow(vec);
        }

        this.repaint();
    }//GEN-LAST:event_buscarClienteActionPerformed

    private void atualizaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizaClienteActionPerformed
        
        if (!novoEndereco.getText().equals("") && !novoTelefone.getText().equals("") && !novoNome.getText().equals("") && !novoCPF.equals("")) {
            controladorCliente.atualizaCliente(novoNome.getText(), novoCPF.getText(), novoEndereco.getText(), novoTelefone.getText(), cpfSelecionado);
            JOptionPane.showMessageDialog(this, "Cliente atualizado com sucesso", "Warning", JOptionPane.WARNING_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "Campos precisam ser preenchidos", null, JOptionPane.OK_OPTION);

        }
    }//GEN-LAST:event_atualizaClienteActionPerformed

    private void checkCPFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkCPFActionPerformed
        if (checkCPF.isSelected()) {
            campoBuscaCPF.setEnabled(true);
            checkNome.setSelected(false);
            campoBuscaNome.setEnabled(false);
        } else {
            campoBuscaCPF.setEnabled(false);
        }
    }//GEN-LAST:event_checkCPFActionPerformed

    private void checkNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkNomeActionPerformed
        if (checkNome.isSelected()) {
            campoBuscaNome.setEnabled(true);
            campoBuscaCPF.setEnabled(false);
            checkCPF.setSelected(false);
        } else {
            campoBuscaNome.setEnabled(false);
        }
    }//GEN-LAST:event_checkNomeActionPerformed

    private void selecionaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selecionaClienteActionPerformed
        try {
            int selecionado = tabelaClientes.getSelectedRow();
            Cliente clienteSelecionado = clientes.get(selecionado);
            novoNome.setText(clienteSelecionado.getNome());
            novoCPF.setText(clienteSelecionado.getCpf_cnpj());
            novoEndereco.setText(clienteSelecionado.getEndereco());
            novoTelefone.setText(clienteSelecionado.getTelefone());
            cpfSelecionado = clienteSelecionado.getCpf_cnpj();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Um cliente deve ser selecionado na tabela", null, JOptionPane.OK_OPTION);

        }
    }//GEN-LAST:event_selecionaClienteActionPerformed

    private void removerClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removerClienteActionPerformed
        if (!cpfSelecionado.equals("") && cpfSelecionado!=null && tabelaClientes.getSelectedRow()!=-1) {
            controladorCliente.deletaClientesPorCPFCNPJ(cpfSelecionado);
            JOptionPane.showMessageDialog(this, "Cliente removido com sucesso", "Warning", JOptionPane.WARNING_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "Um cliente deve ser selecionado na Tabela", null, JOptionPane.OK_OPTION);
        }
    }//GEN-LAST:event_removerClienteActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane abasUsuario;
    private javax.swing.JButton adicionarUsuario;
    private javax.swing.JButton atualizaCliente;
    private javax.swing.JToolBar barraCliente;
    private javax.swing.JButton botaoConfirmarUsuario;
    private javax.swing.JButton buscarCliente;
    private javax.swing.JTextField campoBuscaCPF;
    private javax.swing.JTextField campoBuscaNome;
    private javax.swing.JTextField campoCPFAddCliente;
    private javax.swing.JTextField campoEnderecoAddCliente;
    private javax.swing.JTextField campoNomeAddCliente;
    private javax.swing.JTextField campoTelefoneAddCliente;
    private javax.swing.JButton cancelarBotao;
    private javax.swing.JCheckBox checkCPF;
    private javax.swing.JCheckBox checkNome;
    private javax.swing.JButton editarUsuario;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField novoCPF;
    private javax.swing.JTextField novoEndereco;
    private javax.swing.JTextField novoNome;
    private javax.swing.JTextField novoTelefone;
    private javax.swing.JButton removerCliente;
    private javax.swing.JButton selecionaCliente;
    private javax.swing.JTable tabelaClientes;
    // End of variables declaration//GEN-END:variables
}
